package tpf.designer.pattern.course5.structure_pattern2.flyweight_13.compound;

import org.apache.log4j.Logger;
import org.junit.Test;

/**
 * Client对象，通常会维持一个对flyweight的引用，
 * 计算或存储一个或多个flyweight的外部状态
 */
public class Client {

    public static final Logger LOGGER = Logger.getLogger(Client.class);

    @Test
    public void testCompound(){
//        FlyweightFactory flyweightFactory = new FlyweightFactory();
        FlyweightFactory flyweightFactory = FlyweightFactory.getInstance();
        Flyweight flyweight = flyweightFactory.factory("bc");
        flyweight.operation("Composite Call");

        flyweight = flyweightFactory.factory('a');
        flyweight.operation("Simple Call");

        flyweight = flyweightFactory.factory('a');
        flyweight.operation("Simple Call12");

        flyweight = flyweightFactory.factory('b');
        flyweight.operation("Simple Call12");

        flyweight = flyweightFactory.factory('b');
        flyweight.operation("Simple Call12");

        flyweightFactory.checkFlyweight();
        LOGGER.info(FlyweightFactory.getInstance().getUseTimes("b"));
    }
}
